import request from '@/utils/request'
import { urlPrefix } from './config'
import qs from 'qs'

/**
 * 获取账户列表
 * @param query
 */
export function getAccountList(query) {
  const queryString = qs.stringify(query)

  return request({
    url: `${urlPrefix}/setting/account?${queryString}`,
    method: 'get'
  })
}

/**
 * 新增账户
 * @param data
 */
export function createAccount(data) {
  return request({
    url: `${urlPrefix}/setting/account`,
    method: 'post',
    data
  })
}

/**
 * 修改账户
 * @param data
 */
export function updateAccount(data) {
  return request({
    url: `${urlPrefix}/setting/account/${data.id}`,
    method: 'patch',
    data
  })
}

/**
 * 删除账户
 * @param id
 */
export function deleteAccount(id) {
  return request({
    url: `${urlPrefix}/setting/account/${id}`,
    method: 'delete'
  })
}

/**
 * 获取权限列表
 */
export function getRoleList() {
  return request({
    url: `${urlPrefix}/setting/roles`,
    method: 'get'
  })
}

/**
 * 给用户添加多角色
 * @param data
 */
export function addRoleToUser(data) {
  return request({
    url: `${urlPrefix}/setting/add_roles`,
    method: 'post',
    data
  })
}
